//
//  KeChengNectVC.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/17.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "KeChengNectVC.h"

@interface KeChengNectVC ()<KeChengNextNavSelectedDelegate>

@end

@implementation KeChengNectVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)initSubView{
    self.mainw = MAINW;
    self.view.backgroundColor = MAINBACKCOLOR;
    [self.view addSubview:self.mainScrollView];
    [self.view addSubview:self.navView];
    [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.equalTo(@44);
    }];
    
    [_mainScrollView addSubview:self.leftKeChengView];
    [_mainScrollView addSubview:self.keChengXueShengZiYuanView];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeView:) name:@"ChangeCellSpaNotice" object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeView:) name:@"TeachChangeNotice" object:nil];
}
#pragma mark - 这个基本每个类都要用
- (void)changeView:(NSNotification *)info{
    int type = [[info.userInfo objectForKey:@"Type"] intValue];
    _mainw = [PublickFunctionObject currentScreenSize:type];
    NSLog(@"view宽度 %f",_mainw);
    _mainScrollView.frame = CGRectMake(0,44, self.mainw, self.view.frame.size.height);
    _mainScrollView.contentSize = CGSizeMake(_mainw*2, 0);
    _mainScrollView.contentOffset = CGPointMake(_mainw*currentIndex, 0);
    
    _navView.frame = CGRectMake(0, 0, _mainw, 44);

    //课程学生
    _leftKeChengView.frame = CGRectMake(0, 0, _mainw, self.view.frame.size.height);
    [_leftKeChengView.tableList reloadData];
    //课程资源
    _keChengXueShengZiYuanView.frame = CGRectMake(_mainw,0, _mainw, self.view.frame.size.height);
    [_keChengXueShengZiYuanView.tableList reloadData];
}
- (KeChengNextNavView *)navView{
    if (!_navView) {
        KeChengNextNavView *topView = [[KeChengNextNavView alloc]init];
        topView.frame = CGRectMake(0, 0, _mainw, 44);
        topView.delegate = self;
        _navView = topView;
    }
    return _navView;
}
- (KeChengXueNextWoDeZiYuanView *)keChengXueShengZiYuanView{
    if (!_keChengXueShengZiYuanView) {
        KeChengXueNextWoDeZiYuanView *view = [[KeChengXueNextWoDeZiYuanView alloc]initWithFrame:CGRectMake(self.mainw, 0, self.mainw, self.view.frame.size.height)];
        _keChengXueShengZiYuanView = view;
    }
    return _keChengXueShengZiYuanView;
}
- (KeChengXueShengView *)leftKeChengView{
    if (!_leftKeChengView) {
        KeChengXueShengView *view = [[KeChengXueShengView alloc]initWithFrame:CGRectMake(0, 0, self.mainw,self.view.frame.size.height)];
        _leftKeChengView = view;
    }
    return _leftKeChengView;
}
- (void)leftButtonClick{
    currentIndex = 0;
    _mainScrollView.contentOffset = CGPointMake(0, 0);
}
- (void)rightButtonClick{
    currentIndex = 1;
    _mainScrollView.contentOffset = CGPointMake(_mainw, 0);
}
- (void)backClick{
    [UIView animateWithDuration:0.5 animations:^{
        self.view.frame= CGRectMake(self->_mainw, 0, self->_mainw, self.view.frame.size.height);
    } completion:^(BOOL finished) {
        [self.view removeFromSuperview];
        self.view = nil;
    }];
    
}
- (UIScrollView *)mainScrollView{
    if (!_mainScrollView) {
        UIScrollView *view = [[UIScrollView alloc]init];
        view.frame = CGRectMake(0, 44, MAINW, APP_HEIGHT-84);
        view.contentSize = CGSizeMake(MAINW*2, 0);
        view.showsHorizontalScrollIndicator = YES;
        view.showsVerticalScrollIndicator = NO;
        view.pagingEnabled = YES;
        view.scrollEnabled = NO;
        view.backgroundColor = MAINBACKCOLOR;
        _mainScrollView = view;
    }
    return _mainScrollView;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
